﻿<div ng-controller="Finance_PayInfoListC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">列表</h1>
    </div>
    <div class="wrapper-md" style="text-align: center;">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12" style="float: right">
                    <a class="btn btn-sm btn-default" href="/api/Finance/ExpPaymentInfo">
                        <i class="fa fa-download text"></i>
                        <span class="text">全部导出</span>
                    </a>
                </div>
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 input-group">
                    <span class="input-group-addon">按名称查找</span>
                    <input type="text" class="form-control" id="customerName" placeholder="按名称查找" ng-model="customerName">
                    <span class="input-group-addon">按状态查找</span>
                    <select class="form-control" id="typename" ng-model="typename">
                        <option value="">请选择状态</option>
                        <option value="0">审批中</option>
                        <option value="1">待确认</option>
                        <option value="2">审批驳回</option>
                        <option value="3">已确认</option>
                        <option value="4">未通过</option>
                    </select>

                    <span class="input-group-addon">按户头类型查找</span>
                    <select class="form-control" id="accounttype" ng-model="accounttype">
                        <option value="">请选择户头类型</option>
                        <option value="0">公户</option>
                        <option value="1">私户</option>
                    </select>

                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" ng-click="find()">查找</button>
                    </span>
                </div>
            </div>
            <div class="table-responsive">
                <table id="example1" class="table table-striped b-t b-light table-bordered">
                    <thead>
                    <tr>
                        <th style="text-align: center;">款项类型</th>
                        <th style="text-align: center;">申请人</th>
                        <th style="text-align: center;">客户</th>
                        <th style="text-align: center;">户头</th>
                        <th style="text-align: center;">金额</th>
                        <th style="text-align: center;">账户</th>
                        <th style="text-align: center;">创建时间</th>
                        <th style="text-align: center;">备注</th>
                        <th style="text-align: center;">状态</th>
                        <th style="text-align: center;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="item in pageData.Data">
                        <td ng-if="item.PaymentStatus == 1" style="width: 5%">退款</td>
                        <td ng-if="item.PaymentStatus == 0" style="width: 5%">报款</td>
                        <td style="width: 10%">{{item.CustomerAgent.Name}}</td>
                        <td style="width: 10%">{{item.Customer.ShortName}}</td>
                        <td style="width: 20%">{{item.Account.Name}}</td>
                        <td style="width: 5%">{{item.Sum | number:2}}</td>
                        <td style="width: 12%">{{item.ToAccount}}</td>
                        <td style="width: 15%">{{item.CreateTime}}</td>
                        <td style="width: 15%">{{item.Remark}}</td>
                        <td ng-if="item.State == 0" style="width: 8%">审批中</td>
                        <td ng-if="item.State == 1" style="width: 8%">待确认</td>
                        <td ng-if="item.State == 2" style="width: 8%">审批驳回</td>
                        <td ng-if="item.State == 3" style="width: 8%">已确认</td>
                        <td ng-if="item.State == 4" style="width: 8%">未通过</td>
                        <td style="width: 10%">
                            <button class="btn btn-sm btn-default" ng-click="appr(item)" ng-disabled="item.State!=1" data-toggle="modal" data-target="#dlg">
                                <i class="fa fa-check-square-o text"></i>
                                <span class="text">确认</span>
                            </button>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="dlg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">报款详情</h4>
                </div>
                <form name="form" class="form-validation">
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="recipient-name" class="control-label">报款人:</label>
                            <input type="text" disabled="disabled" class="form-control" id="recipient-name" ng-model="NowData.CustomerAgent.Name">
                        </div>
                        <div class="form-group">
                            <label class="control-label">客户</label>
                            <input type="text" disabled="disabled" class="form-control" ng-model="NowData.Customer.ShortName">

                        </div>
                        <div class="form-group">
                            <label class="control-label">户头</label>
                            <input type="text" disabled="disabled" class="form-control" ng-model="NowData.Account.Name">
                        </div>
                        <div class="form-group">
                            <label class="control-label">金额</label>
                            <input type="text" disabled="disabled" class="form-control" ng-model="NowData.Sum">
                        </div>
                        <div class="form-group">
                            <label class="control-label">报款时间</label>
                            <input type="text" disabled="disabled" class="form-control" ng-model="NowData.PaymentTime">
                        </div>
                        <div class="form-group">
                            <label class="control-label">备注</label>
                            <input type="text" disabled="disabled" class="form-control" ng-model="NowData.Remark">
                        </div>
                        <div class="form-group">
                            <label class="control-label">收款账户</label>
                            <input type="text" disabled="disabled" class="form-control" ng-model="NowData.ToAccount">
                        </div>
                        <div class="form-group">
                            <label class="control-label">审批意见</label>
                            <input type="text" class="form-control" ng-model="NowData.ApprovalRemark">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" ng-disabled="form.$invalid" data-dismiss="modal"  ng-click="pass(true)">确认单据</button>
                        <button type="button" class="btn btn-default" ng-disabled="form.$invalid" data-dismiss="modal"  ng-click="pass(false)">取消单据</button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    angular.module('app')//非标优惠
.controller("Finance_PayInfoListC", function($scope, $state, $http,toSave) {
        $scope.pageData = {};
        $scope.customerName = "";
        $scope.typename = "";
        $scope.accounttype = "";
        $scope.pageData.Page = 0;
        $scope.customerName = "";
        $scope.pageData.Rows = $scope.defPageRows;
        //
        $scope.getData = function(p, r) {
            if (p) {
                p = p < 1 ? 1 : p;
            } else p = 1;
            if (r) {
            } else r = $scope.defPageRows;
            toSave.save_pages_lis(p,r);//保存当前页码和条数
            
            debugger;
            $http({
                    url: "/api/Finance/PaymentInfo",
                    method: "GET",
                    params: { page: p, rows: r, customerName: $scope.customerName, state: $scope.typename, accounttype: $scope.accounttype }
                })
                .then(function (res) {
                    debugger;
                    $scope.pageData = res.data;
                    console.log($scope.pageData);
                })
                .then(function (error) {
                    debugger;
                    if (error) {
                        alert("数据获取失败");
                    }
                });
        };
        // $scope.getData(1, $scope.pageData.Rows);
        $scope.pass = function(isPass) {
            console.log(isPass);
            if ($scope.NowData.PaymentStatus == 1){
                $http.post("../api/Finance/RefundConfirm?paymentInfoId=" + $scope.NowData.Id + "&money=" + $scope.NowData.Sum + "&pass=" + isPass + "&approvalRemark=" + $scope.NowData.ApprovalRemark)
                        .then(function() {
                            alert("已提交");
                            $scope.getData(toSave.get_pages(), toSave.get_lis());
                        }, function() {
                            alert("处理异常");
                        });
            }else if ($scope.NowData.PaymentStatus == 0){
                $http.put("../api/Finance?paymentInfoId=" + $scope.NowData.Id + "&money=" + $scope.NowData.Sum + "&pass=" + isPass + "&approvalRemark=" + $scope.NowData.ApprovalRemark+"&clientId=" +$scope.NowData.CustomerAgent.Id)
                        .then(function() {
                            alert("已提交");
                            $scope.getData(toSave.get_pages(), toSave.get_lis());
                        }, function() {
                            alert("处理异常");
                        });
            }
        };

        $scope.appr = function(item) {
            $scope.NowData = item;
        };
        $scope.find = function(){
            $scope.getData(1, $scope.pageData.Rows);
             toSave.save_inputs();//点击查询先保存input里面的值
                console.log(toSave.get_inputs('findname'))
        }
        if (toSave.get_inputs('findname')) {
                    $scope.findname=toSave.get_inputs('findname');//把保存该id名的值取出来赋值给input框
                    // alert(111)
                    $scope.getData(toSave.get_pages(), toSave.get_lis());
                    console.log(toSave.get_pages(), toSave.get_lis());
         }else{
                    $scope.getData(toSave.get_pages(), $scope.pageData.Rows);
         }

    })

</script>
<script src="js/services/toSave.js"></script>

